package cn.etgps.etgps.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.etgps.etgps.R;


public class ExpandButton extends LinearLayout {
    private Context mContext = null;
    private TextView mName = null;
    private ImageView mIcon = null;

    public ExpandButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        initUI(context);
    }

    public ExpandButton(Context context) {
        super(context);
        initUI(context);
    }

    //解析布局组成button
    private void initUI(Context context) {
        mContext = context;
        LayoutInflater mInflater = LayoutInflater.from(context);
        View view = mInflater.inflate(R.layout.expand_btn, null);
        this.addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        mName = (TextView) view.findViewById(R.id.btn_name);
        mIcon = (ImageView) view.findViewById(R.id.btn_icon);
    }

    //按钮名
    public void setButtonName(String name) {
        mName.setText(name);
    }

    //展开、收起图片展示
    public void expandButton(boolean isExpand) {
        if (isExpand) {
            mIcon.setBackgroundResource(R.drawable.icon_arrow_close);
        } else {
            mIcon.setBackgroundResource(R.drawable.icon_arrow_open);
        }
    }
}
